//+------------------------------------------------------------------+
//|                                               Advanced forecater |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Maroon//Black//DarkGray
#property indicator_color2 Orange
#property indicator_color3 Orange
#property indicator_color4 LimeGreen
#property indicator_color5 LimeGreen
#property indicator_color6 clrMagenta
#property indicator_color7 Orange
#property indicator_color8 LimeGreen
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 2
#property indicator_width4 3
#property indicator_width5 3
#property indicator_width7 2
#property indicator_width8 2

//
//
enum enTimeFrames
{
   tf_cu  = PERIOD_CURRENT, // Current time frame
   tf_m1  = PERIOD_M1,      // 1 minute
   tf_m5  = PERIOD_M5,      // 5 minutes
   tf_m15 = PERIOD_M15,     // 15 minutes
   tf_m30 = PERIOD_M30,     // 30 minutes
   tf_h1  = PERIOD_H1,      // 1 hour
   tf_h4  = PERIOD_H4,      // 4 hours
   tf_d1  = PERIOD_D1,      // Daily
   tf_w1  = PERIOD_W1,      // Weekly
   tf_mn1 = PERIOD_MN1,     // Monthly
   tf_n1  = -1,             // First higher time frame
   tf_n2  = -2,             // Second higher time frame
   tf_n3  = -3              // Third higher time frame
};
//
//
//

extern enTimeFrames TimeFrame      = tf_cu;
extern ENUM_APPLIED_PRICE Price       = PRICE_CLOSE;
extern int             FastEma        = 13;
extern int             SlowEma        = 34;
extern int             SignalMA       = 8;
extern ENUM_MA_METHOD  SignalMAMode   = MODE_EMA;
extern int             SigMA          = 8;
extern ENUM_MA_METHOD  SigMAMode      = MODE_EMA;
extern bool   alertsOn               = true;
extern bool   alertsOnCurrent        = false;
extern bool   alertsMessage          = true;
extern bool   alertsSound            = false;
extern bool   alertsEmail            = false;
extern bool   ShowText               = true;
extern string TextDir                = "advanced forecaster Text";
extern int    textCorner             = 1;
extern int    textXPosition          = 10;
extern int    textYPosition          = 10;
extern color  upTextColor            = Blue;
extern color  dnTextColor            = Red;
extern int    upFontSize             = 12;
extern int    dnFontSize             = 12;   
extern bool   verticalLinesVisible   = false;//true;//;
extern bool   linesOnFirst           = false;//true;
extern string verticalLinesID        = "advanced forecaster Lines";
extern color  verticalLinesUpColor   = Blue;//DeepSkyBlue;
extern color  verticalLinesDnColor   = Red;//PaleVioletRed;
extern ENUM_LINE_STYLE verticalLinesStyle = STYLE_SOLID;//DOT;
extern int    verticalLinesWidth     = 2;//0;
extern bool   Interpolate            = true;

extern bool   drawArrows             = false;//true; 
extern bool   ArrowsOnFirstBar       = false;//true;    

//
extern string             button_note1          = "------------------------------";
extern int                btn_Subwindow = 0;
extern ENUM_BASE_CORNER   btn_corner            = CORNER_LEFT_UPPER; 
extern string             btn_text              = "advFo";
extern string             btn_Font              = "Arial";
extern int                btn_FontSize          = 10;                            
extern color              btn_text_ON_color     = clrLime;
extern color              btn_text_OFF_color    = clrRed;
extern string             btn_pressed           = "advFo OFF";            
extern string             btn_unpressed         = "advFo ON";
extern color              btn_background_color  = clrDimGray;
extern color              btn_border_color      = clrBlack;
extern int                button_x              = 850;                                 
extern int                button_y              = 20;                                   
extern int                btn_Width             = 65;                                 
extern int                btn_Height            = 20;                                
extern string             soundBT               = "tick.wav";  
extern string             button_note2          = "------------------------------";

bool                      show_data             = true;
string IndicatorName, IndicatorObjPrefix ,buttonId ;
//
//
//
//

double temp1[];
double temp2[];
double sum[],sig[];
double sumua[];
double sumub[];
double sumda[];
double sumdb[];
double dotu[];
double dotd[];
double state[];

string indicatorFileName;
bool   returnBars;

string GenerateIndicatorName(const string target)
{
   string name = target;
   int try = 2;
   while (WindowFind(name) != -1)
   {
      name = target + " #" + IntegerToString(try++);
   }
   return name;
}


//------------------------------------------------------------------
//
//------------------------------------------------------------------

int init() 
{
   for (int i=0; i<indicator_buffers; i++) SetIndexStyle(i,DRAW_LINE);
   IndicatorBuffers(11);   
   SetIndexBuffer(0,sum);   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(1,sumua); SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(2,sumub); SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(3,sumda); SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(4,sumdb); SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(5,sig);   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(6,dotu);  if (drawArrows) { SetIndexStyle(6,DRAW_ARROW); SetIndexArrow(6,234); } else SetIndexStyle(6,DRAW_NONE);
   SetIndexBuffer(7,dotd);  if (drawArrows) { SetIndexStyle(7,DRAW_ARROW); SetIndexArrow(7,233); } else SetIndexStyle(7,DRAW_NONE);
   SetIndexBuffer(8,temp1);
   SetIndexBuffer(9,temp2);
   SetIndexBuffer(10,state);
      indicatorFileName = WindowExpertName();
      returnBars        = (TimeFrame==-99);
      TimeFrame         = (enTimeFrames)timeFrameValue(TimeFrame);
   IndicatorShortName(timeFrameToString(TimeFrame)+" Advanced_forecater");
   
   IndicatorName = GenerateIndicatorName(btn_text);
   IndicatorObjPrefix = "__" + IndicatorName + "__";
   IndicatorShortName(WindowExpertName());
   IndicatorDigits(Digits);
      double val;
   if (GlobalVariableGet(IndicatorName + "_visibility", val))
   show_data = val != 0;

   ChartSetInteger(ChartID(), CHART_EVENT_MOUSE_MOVE, 1);
   buttonId = IndicatorObjPrefix+btn_text;
   createButton(buttonId, btn_text, btn_Width, btn_Height, btn_Font, btn_FontSize, btn_background_color, btn_border_color, btn_text_ON_color);
   ObjectSetInteger(ChartID(), buttonId, OBJPROP_YDISTANCE, button_y);
   ObjectSetInteger(ChartID(), buttonId, OBJPROP_XDISTANCE, button_x);
   
     
   
   return (0);
}


void createButton(string buttonID,string buttonText,int width,int height,string font,int fontSize,color bgColor,color borderColor,color txtColor)
{
      ObjectDelete    (ChartID(),buttonID);
      ObjectCreate (ChartID(),buttonID,OBJ_BUTTON,btn_Subwindow,0,0);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_COLOR,txtColor);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_BGCOLOR,bgColor);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_BORDER_COLOR,borderColor);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_XSIZE,width);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_YSIZE,height);
      ObjectSetString (ChartID(),buttonID,OBJPROP_FONT,font);
      ObjectSetString (ChartID(),buttonID,OBJPROP_TEXT,buttonText);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_FONTSIZE,fontSize);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_SELECTABLE,0);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_CORNER,btn_corner);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_HIDDEN,1);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_XDISTANCE,9999);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_YDISTANCE,9999);
}



int deinit() 
{  
ObjectsDeleteAll(0,"advFo");
   ObjectsDeleteAll(ChartID(), IndicatorObjPrefix);
   

   ObjectDelete(TextDir);
   deleteLines();
return(0); 
}

//
//
//
bool recalc = true;
 void handleButtonClicks()
{
   if (ObjectGetInteger(ChartID(), buttonId, OBJPROP_STATE))
   {
      ObjectSetInteger(ChartID(), buttonId, OBJPROP_STATE, false);
      show_data = !show_data;
      GlobalVariableSet(IndicatorName + "_visibility", show_data ? 1.0 : 0.0);
      recalc = true;
      start();
   }
}
void OnChartEvent(const int id, 
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   handleButtonClicks();
   if (id==CHARTEVENT_OBJECT_CLICK && ObjectGet(sparam,OBJPROP_TYPE)==OBJ_BUTTON)
   {
   if (soundBT!="") PlaySound(soundBT);     
   }
}
//
//
int start() 
{
 handleButtonClicks();
   recalc = false;
   
   start2();
     SetIndexStyle(0,DRAW_LINE);
     SetIndexStyle(1,DRAW_LINE);
     SetIndexStyle(2,DRAW_LINE);
     SetIndexStyle(3,DRAW_LINE);
    SetIndexStyle(4,DRAW_LINE);
     SetIndexStyle(5,DRAW_LINE);
     if (drawArrows) { SetIndexStyle(6,DRAW_ARROW); SetIndexArrow(6,234); } else SetIndexStyle(6,DRAW_NONE);
    if (drawArrows) { SetIndexStyle(7,DRAW_ARROW); SetIndexArrow(7,233); } else SetIndexStyle(7,DRAW_NONE);
       
      
   
   if (show_data)
      {
      ObjectSetInteger(ChartID(),buttonId,OBJPROP_COLOR,btn_text_ON_color);
      ObjectSetString(ChartID(),buttonId,OBJPROP_TEXT,btn_unpressed);
      }
      else
      {
      ObjectSetInteger(ChartID(),buttonId,OBJPROP_COLOR,btn_text_OFF_color);
      ObjectSetString(ChartID(),buttonId,OBJPROP_TEXT,btn_pressed);
      SetIndexStyle(0,DRAW_NONE);
        SetIndexStyle(1,DRAW_NONE);
        SetIndexStyle(2,DRAW_NONE);
        SetIndexStyle(3,DRAW_NONE);
        SetIndexStyle(4,DRAW_NONE);
        SetIndexStyle(5,DRAW_NONE);
        SetIndexStyle(6,DRAW_NONE);
        SetIndexStyle(7,DRAW_NONE);
      ObjectDelete(TextDir);  
       
   
      //template code     
      }
       return(0);
      }
//

int start2() 
{
   int countedBars = IndicatorCounted();
      if(countedBars<0) return(-1);
      if(countedBars>0) countedBars--;
         int i,limit = MathMin(Bars-countedBars,Bars-1);
            if (returnBars) { sum[0] = limit+1; return(0); }
            if (TimeFrame!=Period())
            {
                     int shift = -1; if (ArrowsOnFirstBar) shift=1;
                     limit = MathMax(limit,MathMin(Bars,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period()));
                     if (state[limit]== 1) CleanPoint(limit,sumua,sumub);
                     if (state[limit]==-1) CleanPoint(limit,sumda,sumdb);
                        for(i=limit; i>=0; i--)
                        {
                           int y = iBarShift(NULL,TimeFrame,Time[i]);
                           int x = iBarShift(NULL,TimeFrame,Time[i+shift]);
                           sum[i]   = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,Price,FastEma,SlowEma,SignalMA,SignalMAMode,SigMA,SigMAMode,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,ShowText,TextDir,textCorner,textXPosition,textYPosition,upTextColor,dnTextColor,upFontSize,dnFontSize,verticalLinesVisible,linesOnFirst,verticalLinesID,verticalLinesUpColor,verticalLinesDnColor,verticalLinesStyle,verticalLinesWidth,Interpolate,drawArrows,ArrowsOnFirstBar,button_note1,btn_Subwindow,btn_corner,btn_text,btn_Font,btn_FontSize,btn_text_ON_color,btn_text_OFF_color,btn_pressed,btn_unpressed,btn_background_color,btn_border_color,button_x,button_y,btn_Width,btn_Height,soundBT,button_note2,0,y);
                           sig[i]   = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,Price,FastEma,SlowEma,SignalMA,SignalMAMode,SigMA,SigMAMode,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,ShowText,TextDir,textCorner,textXPosition,textYPosition,upTextColor,dnTextColor,upFontSize,dnFontSize,verticalLinesVisible,linesOnFirst,verticalLinesID,verticalLinesUpColor,verticalLinesDnColor,verticalLinesStyle,verticalLinesWidth,Interpolate,drawArrows,ArrowsOnFirstBar,button_note1,btn_Subwindow,btn_corner,btn_text,btn_Font,btn_FontSize,btn_text_ON_color,btn_text_OFF_color,btn_pressed,btn_unpressed,btn_background_color,btn_border_color,button_x,button_y,btn_Width,btn_Height,soundBT,button_note2,5,y);
                           state[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,Price,FastEma,SlowEma,SignalMA,SignalMAMode,SigMA,SigMAMode,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,ShowText,TextDir,textCorner,textXPosition,textYPosition,upTextColor,dnTextColor,upFontSize,dnFontSize,verticalLinesVisible,linesOnFirst,verticalLinesID,verticalLinesUpColor,verticalLinesDnColor,verticalLinesStyle,verticalLinesWidth,Interpolate,drawArrows,ArrowsOnFirstBar,button_note1,btn_Subwindow,btn_corner,btn_text,btn_Font,btn_FontSize,btn_text_ON_color,btn_text_OFF_color,btn_pressed,btn_unpressed,btn_background_color,btn_border_color,button_x,button_y,btn_Width,btn_Height,soundBT,button_note2,10,y);
                           sumua[i] = EMPTY_VALUE;
                           sumub[i] = EMPTY_VALUE;
                           sumda[i] = EMPTY_VALUE;
                           sumdb[i] = EMPTY_VALUE;
                        if(x!=y)
                        {
                           dotu[i]  = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,Price,FastEma,SlowEma,SignalMA,SignalMAMode,SigMA,SigMAMode,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,ShowText,TextDir,textCorner,textXPosition,textYPosition,upTextColor,dnTextColor,upFontSize,dnFontSize,verticalLinesVisible,linesOnFirst,verticalLinesID,verticalLinesUpColor,verticalLinesDnColor,verticalLinesStyle,verticalLinesWidth,Interpolate,drawArrows,ArrowsOnFirstBar,button_note1,btn_Subwindow,btn_corner,btn_text,btn_Font,btn_FontSize,btn_text_ON_color,btn_text_OFF_color,btn_pressed,btn_unpressed,btn_background_color,btn_border_color,button_x,button_y,btn_Width,btn_Height,soundBT,button_note2,6,y);
                           dotd[i]  = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,Price,FastEma,SlowEma,SignalMA,SignalMAMode,SigMA,SigMAMode,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,ShowText,TextDir,textCorner,textXPosition,textYPosition,upTextColor,dnTextColor,upFontSize,dnFontSize,verticalLinesVisible,linesOnFirst,verticalLinesID,verticalLinesUpColor,verticalLinesDnColor,verticalLinesStyle,verticalLinesWidth,Interpolate,drawArrows,ArrowsOnFirstBar,button_note1,btn_Subwindow,btn_corner,btn_text,btn_Font,btn_FontSize,btn_text_ON_color,btn_text_OFF_color,btn_pressed,btn_unpressed,btn_background_color,btn_border_color,button_x,button_y,btn_Width,btn_Height,soundBT,button_note2,7,y);
                        }
                        else
                        {
                           dotu[i]  = EMPTY_VALUE;
                           dotd[i]  = EMPTY_VALUE;
                        }
                        
                           //
                           //
                           //
                           //
                           //
                        
                           if (!Interpolate || (i>0 && y==iBarShift(NULL,TimeFrame,Time[i-1]))) continue;
                           
                           //
                           //
                           //
                           //
                           //
                           
                           datetime time = iTime(NULL,TimeFrame,y);
                              for(int n = 1; i+n < Bars && Time[i+n] >= time; n++) continue;	
                              for(int l = 1; l < n && (i+l<Bars) && (i+n)<Bars; l++)
                              {
                                 sum[i+l]  = sum[i]  + (sum[i+n] -sum[i] )*l/n;
                                 sig[i+l]  = sig[i]  + (sig[i+n] -sig[i] )*l/n;
                              }
                        }                           
                        for(i=limit; i>=0; i--)
                        {
                           if (state[i]== 1) PlotPoint(i,sumua,sumub,sum);
                           if (state[i]==-1) PlotPoint(i,sumda,sumdb,sum);
                        }                              
                  return(0);
            }

   //
   //
   //
   //
   //

   double Multiply_Factor_1 = 2.0 / (FastEma + 1.0);
   double Multiply_Factor_2 = 2.0 / (SlowEma + 1.0);
   double Multiply_Factor_3 = Multiply_Factor_1 - Multiply_Factor_2;
      if (MathAbs(Multiply_Factor_3) == 0.0) return(0);
 
   //
   //
   //
   //
   //
   
   if (state[limit]== 1) CleanPoint(limit,sumua,sumub);
   if (state[limit]==-1) CleanPoint(limit,sumda,sumdb);
   for(i=limit; i>=0; i--) temp1[i] = iMA(NULL,0,FastEma,0,MODE_EMA, Price,i)-iMA(NULL,0,SlowEma,0,MODE_EMA,Price,i);
   for(i=limit; i>=0; i--) temp2[i] = iMAOnArray(temp1,0,SignalMA,0,SignalMAMode,i);
   for(i=limit; i>=0; i--)
   {
      sumua[i] = EMPTY_VALUE;
      sumub[i] = EMPTY_VALUE;
      sumda[i] = EMPTY_VALUE;
      sumdb[i] = EMPTY_VALUE;
      dotu[i]  = EMPTY_VALUE;
      dotd[i]  = EMPTY_VALUE;
      sum[i]   = (Multiply_Factor_1 * iMA(NULL,0,FastEma,0,MODE_EMA,Price,i)+iMA(NULL,0,SlowEma,0,MODE_EMA,Price,i) - 
                                      iMA(NULL,0,FastEma,0,MODE_EMA,Price,i)-Multiply_Factor_2*iMA(NULL,0,SlowEma,0,MODE_EMA,Price,i) + temp2[i]) / Multiply_Factor_3;
    }
    for(i=limit; i>=0; i--)
    {
      sig[i]   = iMAOnArray(sum,0,SigMA,0,SigMAMode,i);
      state[i] = 0;
         if (sum[i]>High[i]) state[i] =  1; 
         if (sum[i]<Low[i])  state[i] = -1; 
         if (state[i]== 1) PlotPoint(i,sumua,sumub,sum); 
         if (state[i]==-1) PlotPoint(i,sumda,sumdb,sum); 
         if (state[i]!=state[i+1])
         {
            if (state[i]== 1) dotu[i] = sum[i]+iATR(NULL,0,20,i)/2; 
            if (state[i]==-1) dotd[i] = sum[i]-iATR(NULL,0,20,i)/2;   
         }
         
         //
         //
         //
         //
         //
         
         if (verticalLinesVisible)
         {
           deleteLine(Time[i]);
           if (state[i]!= state[i+1])
           {
                if (state[i] == 1) drawLine(i,verticalLinesDnColor);
                if (state[i] ==-1) drawLine(i,verticalLinesUpColor);
           }
         }      
   }
   if (state[0] ==  1) Commenter(-1);
   if (state[0] == -1) Commenter( 1);
   manageAlerts();
   return (0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//

string sTfTable[] = {"M1","M5","M10","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,10,15,30,60,240,1440,10080,43200};

string timeFrameToString(int tf) {
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}
 int timeFrameValue(int _tf)
{
   int add  = (_tf>=0) ? 0 : MathAbs(_tf);
   if (add != 0) _tf = _Period;
   int size = ArraySize(iTfTable); 
      int i =0; for (;i<size; i++) if (iTfTable[i]==_tf) break;
                                   if (i==size) return(_Period);
                                                return(iTfTable[(int)MathMin(i+add,size-1)]);
}
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//

void CleanPoint(int i,double& first[],double& second[])
{
   if ((second[i]  != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))
        second[i+1] = EMPTY_VALUE;
   else
      if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))
          first[i+1] = EMPTY_VALUE;
}

//
//
//
//
//

void PlotPoint(int i,double& first[],double& second[],double& from[])
{
   if (first[i+1] == EMPTY_VALUE)
      {
         if (first[i+2] == EMPTY_VALUE) {
                first[i]   = from[i];
                first[i+1] = from[i+1];
                second[i]  = EMPTY_VALUE;
            }
         else {
                second[i]   =  from[i];
                second[i+1] =  from[i+1];
                first[i]    = EMPTY_VALUE;
            }
      }
   else
      {
         first[i]  = from[i];
         second[i] = EMPTY_VALUE;
      }
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

void manageAlerts()
{
   if (alertsOn)
   {
      if (alertsOnCurrent)
           int whichBar = 0;
      else     whichBar = 1;
      if (state[whichBar]!=state[whichBar+1])
      {
         if (state[whichBar] ==  1) doAlert(whichBar,"down");
         if (state[whichBar] == -1) doAlert(whichBar,"up");
      }         
   }
}

//
//
//
//
//

void doAlert(int forBar, string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
   if (previousAlert != doWhat || previousTime != Time[forBar]) {
       previousAlert  = doWhat;
       previousTime   = Time[forBar];

       //
       //
       //
       //
       //

       message =  StringConcatenate(Symbol()," "+timeFrameToString(Period())+" at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Advanced forecaster trend changeed to ",doWhat);
          if (alertsMessage) Alert(message);
          if (alertsEmail)   SendMail(StringConcatenate(Symbol()," Advanced forecaster "),message);
          if (alertsSound)   PlaySound("alert2.wav");
   }
}

//
//
//
//
//

void drawLine(int i,color theColor)
{
      string name = verticalLinesID+":"+Time[i];
   
      //
      //
      //
      //
      //
      
      int add = 0; if (!linesOnFirst) add = _Period*60-1;
      ObjectCreate(name,OBJ_VLINE,0,Time[i]+add,0);
         ObjectSet(name,OBJPROP_COLOR,theColor);
         ObjectSet(name,OBJPROP_STYLE,verticalLinesStyle);
         ObjectSet(name,OBJPROP_WIDTH,verticalLinesWidth);
         ObjectSet(name,OBJPROP_BACK,true);
}

//
//
//
//
//

void deleteLines()
{
   string lookFor       = verticalLinesID+":";
   int    lookForLength = StringLen(lookFor);
   for (int i=ObjectsTotal()-1; i>=0; i--)
   {
      string objectName = ObjectName(i);
         if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName);
   }
}

//
//
//
//
//

void deleteLine(datetime time)
{
   string lookFor = verticalLinesID+":"+time; ObjectDelete(lookFor);
}

//
//
//
//
//

void Commenter(int Dir) 
{
    if (ShowText)
    {
      ObjectCreate(TextDir,OBJ_LABEL,0,0,0);
         ObjectSet(TextDir,OBJPROP_CORNER,textCorner);
         ObjectSet(TextDir,OBJPROP_XDISTANCE,textXPosition);
         ObjectSet(TextDir,OBJPROP_YDISTANCE,textYPosition);
         if (Dir == 1) ObjectSetText(TextDir, "Buy signal", upFontSize,"Arial",upTextColor);
         if (Dir ==-1) ObjectSetText(TextDir, "Sell signal",dnFontSize,"Arial",dnTextColor);
    }
   
return; 
}